package cn.com.note.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.Gravity;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.RadioGroup;

import cn.com.note.R;
import cn.com.note.utils.ToastUtils;

/**
 * Created by sunfulin on 2019/7/23.
 */

public class CustomToastAc extends AppCompatActivity implements View.OnClickListener {
    int toastGravity = Gravity.BOTTOM;
    boolean isLongTime = false;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_custom_tost);
        findViewById(R.id.bt_show).setOnClickListener(this);
        findViewById(R.id.bt_success).setOnClickListener(this);
        findViewById(R.id.bt_Error).setOnClickListener(this);
        findViewById(R.id.bt_Fail).setOnClickListener(this);
        findViewById(R.id.bt_Waring).setOnClickListener(this);
        RadioGroup radioGroup = findViewById(R.id.radio_group);
        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                    case R.id.top:
                        toastGravity = Gravity.TOP;
                        break;
                    case R.id.center:
                        toastGravity = Gravity.CENTER;
                        break;
                    case R.id.bottom:
                        toastGravity = Gravity.BOTTOM;
                        break;
                }
            }
        });
        CheckBox checkBox = findViewById(R.id.longTime);
        checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                isLongTime = isChecked;
            }
        });
        ToastUtils.builder(getApplicationContext())
                .setMargin(15)
                .setMarginBottom(95)
                .setRadios(5);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.bt_show:
                ToastUtils.showToast("提示信息！", toastGravity, isLongTime);
                break;
            case R.id.bt_success:
                ToastUtils.showSuccess("操作成功！", toastGravity, isLongTime);
                break;
            case R.id.bt_Error:
                ToastUtils.showError("保存失败！", toastGravity, isLongTime);
                break;
            case R.id.bt_Fail:
                ToastUtils.showError("保存失败！", toastGravity, isLongTime);
                break;
            case R.id.bt_Waring:
                ToastUtils.showWaring("不能为空！", toastGravity, isLongTime);
                break;
        }
    }
}
